﻿<!--#include virtual="/Common/Config.asp" -->
<!--#include virtual="/2010admin/Check_IsLogin.asp" -->
<!--#include virtual="/Common/Cls_Upload.asp" -->
<!--#include virtual="/Common/Function.asp" -->
<%
Server.ScriptTimeOut = 1800
' 参数变量
Dim sType, sStyleName
' 设置变量
Dim sAllowExt, nAllowSize, sUploadDir, nUploadObject, nAutoDir, sBaseUrl, sContentPath
' 接口变量
Dim sFileExt, sOriginalFileName, sSaveFileName, sPathFileName, nFileNum


Dim sAction
sAction = UCase(Trim(Request.QueryString("action")))

Select Case sAction
Case "SAVE"
	'Call ShowForm()			' 显示上传表单
	Call DoSave()			' 存文件
Case Else
	Call ShowForm()			' 显示上传表单
End Select



Sub ShowForm() 
%>
<HTML>
<HEAD>
<TITLE>文件上传</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>
<body bgcolor=menu>

<form action="?action=save&change_field=<%=requery("change_field")%>" method=post name=myform enctype="multipart/form-data">
<input type=file name=uploadfile size=1 style="width:50%" >
<input type="submit" name="submit" value="上传" class="button">
</form>

<script language=javascript>

var sAllowExt = "jpg|gif";
// 检测上传表单
function CheckUploadForm() {
	if (!IsExt(document.myform.uploadfile.value,sAllowExt)){
		parent.UploadError("提示：\n\n请选择一个有效的文件，\n支持的格式有（"+sAllowExt+"）！");
		return false;
	}
	return true
}

</script>

</body>
</html>
<% 
End Sub 


' 保存操作
Sub DoSave()

	' 默认无组件上传类
	Call DoUpload_Class
	
	'sPathFileName = sSaveFileName
	'Call OutScript("parent.UploadSaved('" & sPathFileName & "');var obj=parent.dialogArguments.dialogArguments;if (!obj) obj=parent.dialogArguments;try{obj.addUploadFile('" & sOriginalFileName & "', '" & sSaveFileName & "', '" & sPathFileName & "');} catch(e){}")

End Sub


Sub DoUpload_Class()

	'On Error Resume Next


	change_field = requery("change_field")

	Dim  Aspto,ImageName,FormName
	Set  Aspto = new Cls_Upload

	aspto.FileType=Upload_FileType
	Aspto.MaxSize = Max_Upload_Size
	Aspto.SavePath=Upload_SavePath
	
	Aspto.UP_Open() 

	For intTemp=1 To Ubound(Aspto.UP_FileItem)
		FormName=Aspto.UP_FileItem(intTemp)
		IF Int(Aspto.Form(FormName&"_Err")) = Int(0) Then
			ImageName = ImageName&Aspto.Form(FormName)&"|"
		Else
			Select Case Aspto.Form(FormName&"_Err")
				Case 1:					
					response.write "<Script language='JavaScript'>window.alert('你上传的文件总大小超出了最大限制（" & Max_Upload_Size & "KB）！');history.back();</Script>"
				Case 2:
					response.write "<Script language='JavaScript'>window.alert('文件格式不对，拒绝上传！');history.back();</Script>"
				Case 3:
					response.write "<Script language='JavaScript'>window.alert('文件太大且格式不对，拒绝上传！');history.back();</Script>"
					
			End Select
		End IF
	Next

	If ImageName<>"" Then
		sSaveFileName = Left(ImageName,Len(ImageName)-1)
	Else
		Set Aspto = nothing 
		AlertBox "请提交有效的上传文件!","javascript:history.go(-1)"
	End If

	Set Aspto = nothing 
	
	'response.Write (sSaveFileName)
	Response.Write "<Script language='JavaScript'>parent.document.form."&change_field&".value='"&sSaveFileName&"';window.location.href='File_Upload.asp?change_field="&change_field&"';</Script>"
	response.End 

End Sub


' 输出客户端脚本
Sub OutScript(str)
	Response.Write "<script language=javascript>" & str & ";history.back()</script>"
End Sub
Sub OutScriptNoBack(str)
	Response.Write "<script language=javascript>" & str & "</script>"
End Sub


' 检测扩展名的有效性
Sub CheckValidExt(sExt)
	Dim b, i, aExt
	b = False
	aExt = Split(sAllowExt, "|")
	For i = 0 To UBound(aExt)
		If LCase(aExt(i)) = sExt Then
			b = True
			Exit For
		End If
	Next
	If b = False Then
		OutScript("parent.UploadError('提示：\n\n请选择一个有效的文件，\n支持的格式有（"+sAllowExt+"）！')")
		Response.End
	End If
End Sub


%>